home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14048 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  965 b 

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!pipeline!news
  2. From: gordo@pipeline.com (Gordo Krefting)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character string
  5. Date: Thu, 11 Apr 1996 17:10:51 GMT
  6. Organization: The Pipeline
  7. Message-ID: <4kj415$3cb@news.nyc.pipeline.com>
  8. References: <4kil74$8i7@Tandem1.opennet.net.au>
  9. NNTP-Posting-Host: pipe12.nyc.pipeline.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. george@opennet.net.au (Kenneth H Smith) wrote:
  13.  
  14. >How do I do a similar statement in C to the Pascal code:
  15.  
  16. >If Ch IN ['a','A'] THEN
  17.  
  18. >I want to execute a piece of code when a particular character is entered
  19. >from the keyboard.
  20.  
  21. >I know I can use if (ch=='a') && (ch=='A') but was looking for something
  22. >a little more ellegant.
  23.  
  24. >Thanks,
  25.  
  26. >Ken Smith.
  27.  
  28. Well, you should probably use:
  29.    if ((ch=='a') || (ch=='A'))
  30. instead!
  31.  
  32.  
  33. You might also want to try:
  34.    if (strchr("aA", ch))
  35.  
  36. be sure to #include <string.h> to get access to the strchr function
  37.  
  38. hth
  39. gordo
  40.     
  41.  
  42.  
  43.  
  44.